package com.dhcc.sdc.busi.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.dhcc.cdc.busi.service.ICdcHospitalService;
import com.dhcc.sdc.busi.service.ISdcBusiOperationLogService;
import com.dhcc.sdc.busi.service.ISdcOperationStatisticsService;
import com.dhcc.sds.base.service.ISdsCommonService;
import com.dhcc.sds.base.service.ISdsQcentityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("${sys.backendPath}/sdc/operstat")
public class SdcOperationStatisticsController {
    private String PREFIX = "/backend/sdc/statistics/";

    private boolean isRole = false;
    @Autowired
    private ISdcOperationStatisticsService sdcOperationStatisticsService;
    @Autowired
    private ICdcHospitalService cdcHospitalService;
    @Autowired
    private ISdsCommonService sdsCommonService;
    @Autowired
    private ISdsQcentityService sdsQcentityService;
    @Autowired
    private ISdcBusiOperationLogService sdcBusiOperationLogService;

    @RequestMapping("")
    public String home(@RequestParam Map<String, Object> map, Model model) {
        //获取部门信息
        JSONArray officMap = cdcHospitalService.getOfficeMap();
        //加载用户关联科室
        JSONArray departMap = sdsCommonService.getDepartMap(new HashMap<>());
        //获取病种
        JSONArray entityMap = sdsQcentityService.getUpEntityMap();
        //日志类型集合
        JSONObject logTypeMap = sdcBusiOperationLogService.logTypeMap();

        model.addAttribute("officeMap", officMap);
        model.addAttribute("departMap", departMap);
        model.addAttribute("entityMap", entityMap);
        model.addAttribute("logTypeMap", logTypeMap);
        model.addAttribute("hospitalId", sdsCommonService.getHospIdBySysUser());
        return  PREFIX + "operationstat.html";
    }

    /**
     * @Description: 顶部和中部的数据查询
     * @Title: homeData
     */
    @RequestMapping("/logData")
    @ResponseBody
    public Object homeData(@RequestParam Map<String, Object> map){
        // 查询登录用户关联科室
        List<String> deptIds = sdsCommonService.getDeptIdsBySysUser();
        map.put("userLinkDepts", deptIds);
        return sdcOperationStatisticsService.getLogData(map);
    }
}
